<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="box">
      <ul>
        <li v-for="v in list">
          <input type="checkbox" v-model="v.check" name="" id="" />
          名字：{{v.name}}
          <button @click=" minusItem(v)">-</button><span>{{v.count}}</span
          ><button @click="addItem(v)">+</button>
          <span>￥ {{v.price}}</span>
          小计：{{v.count*v.price}}
        </li>
      </ul>
      <div>
        <p>全选<input type="checkbox" name="" id="" /></p>
        <p>总数量:{{gross}}</p>
        <p>总价：{{grossNew}}</p>
      </div>
    </div>
    <script>
        Vue.config.productionTip = false
      new Vue({
        el: "#box",
        data: {
          gross: "",
          grossNew:'',
          list: [
            {
              id: 01,
              name: "小米",
              count: 1,
              price: 100,
              check: false,
            },
            {
              id: 02,
              name: "魅族",
              count: 1,
              price: 50,
              check: false,
            },
            {
              id: 03,
              name: "一加",
              count: 1,
              price: 90,
              check: false,
            },
          ],
        },
        methods: {
          //加数量
          addItem(v) {
            console.log(v.count);
            v.count += 1;
            //总数量
           this.gross=this.list.reduce((next, prev) => {
              return next + prev.count;
            }, 0);
            //总价格
            this.grossNew=this.list.reduce((next, prev) => {
              return next + prev.count*prev.price;
            }, 0);
          },
          //减数量
          minusItem(v) {
            v.count -= 1;
              //总数量
           this.gross=this.list.reduce((next, prev) => {
              return next + prev.count;
            }, 0);
            //总价格
            this.grossNew=this.list.reduce((next, prev) => {
              return next + prev.count*prev.price;
            }, 0);
          },
        },
      });
    </script>
  </body>
</html>
